package com.xty.itgroup.tech05tytex.Mapper;

import com.xty.itgroup.tech05tytex.Databean.Bean02Customer;
import com.xty.itgroup.tech05tytex.Databean.Bean02CustomerTicket;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface Mapper02Customer {
    //添加客户
    @Insert("insert into tytex01customer(customer_name,customer_type,customer_code,customer_address,customer_person,customer_phone,contract_num,create_time) values(#{customer_name},#{customer_type},#{customer_code},#{customer_address},#{customer_person},#{customer_phone},0,Now())")
    public abstract void addCustomer(Bean02Customer c);
    //添加客户开票信息
    @Insert("insert into tytex01customer_ticket(customer_id,ticket_name,ticket_address,ticket_account,ticket_bank,ticket_tax,ticket_post_code,ticket_phone,create_time) values(#{customer_id},#{ticket_name},#{ticket_address},#{ticket_account},#{ticket_bank},#{ticket_tax},#{ticket_post_code},#{ticket_phone},Now())")
    public abstract void addCustomerTicket(Bean02CustomerTicket ct);
    //客户开票信息
    @Select("select id,customer_id,ticket_name,ticket_address,ticket_account,ticket_bank,ticket_tax,ticket_post_code,ticket_phone from tytex01customer_ticket where customer_id=#{customer_id}")
    public abstract List<Bean02CustomerTicket> listTicketInfo(int customer_id);
    @Select("select id,customer_id,ticket_name,ticket_address,ticket_account,ticket_bank,ticket_tax,ticket_post_code,ticket_phone from tytex01customer_ticket where id = #{id}")
    public abstract  Bean02CustomerTicket getTicketInfo(int id);
    //简易客户列表
    @Select("select id,customer_name,customer_type,customer_code from tytex01customer")
    public abstract List<Map<String,Object>> simpleListCustomer();
    //客户列表
    @Select("select id,customer_name,customer_type,customer_code,customer_address,customer_person,customer_phone,contract_num from tytex01customer where customer_name like #{customer_name} and IF(#{customer_type}=-1,1=1,customer_type = #{customer_type}) and customer_code like #{customer_code}")
    public abstract List<Bean02Customer> listCustomer(String customer_name,String customer_code,int customer_type);
    //更新流水号
    @Update("update tytex01customer set contract_num=contract_num+1 where id = #{customer_id}")
    public abstract void updateNum(int customer_id);
    //主键查询客户
    @Select("select id,customer_name,customer_type,customer_code,customer_address,customer_person,customer_phone,contract_num from tytex01customer where id= #{customer_id}")
    public abstract Bean02Customer getCustomer(int customer_id);
    //获取合同条款
    @Select("SELECT contract_id,contract_name,contract_content FROM `tytex02contract_clause` where contract_id = #{contract_id}")
    public abstract Map<String, Object> getClause(int contract_id);
    @Update("update tytex01customer set customer_name= #{customer_name},customer_type = #{customer_type},customer_code = #{customer_code},customer_address = #{customer_address},customer_person = #{customer_person},customer_phone = #{customer_phone} where id = #{id}")
    public abstract void updateCustomer(Bean02Customer bc);
}
